<?php

namespace App\Models\Enroll;

class EnrollRepository implements \App\Contracts\Repositories\EnrollRepository
{
    public function insert($prizePayment)
    {
        return Enroll::insert($prizePayment);
    }

    public function create($prizePayment)
    {
        return Enroll::create($prizePayment);
    }

    public function modify($prizePayment, $conditions)
    {
        return Enroll::where($conditions)->update($prizePayment);
    }

    public function update($fields, $conditions)
    {
        return Enroll::whereIn('id', $conditions)->update($fields);
    }

    public function delete($conditions)
    {
        return Enroll::where($conditions)->delete();
    }

    public function findByConditionsPage($condition, $sortArray = [], $limit, $start)
    {
        $qb = Enroll::with('activity')->where($condition)->limit($limit)->skip($start);
        if (!empty($sortArray)) {
            foreach ($sortArray as $sort) {
                $qb = $qb->orderBy($sort[0], $sort[1]);
            }
        }

        return $qb->get();
    }

    public function countByConditions($condition)
    {
        $count = Enroll::with('prize')->where($condition)->count();

        return $count;
    }

    public function find($conditions)
    {
        return Enroll::where($conditions)->first();
    }

    public function findAll($conditions)
    {
        return Enroll::where($conditions)->get();
    }

    /**
     * @param $ids
     *
     * @return mixed
     */
    public function softDelete($ids)
    {
        return Enroll::whereIn('id', $ids)->delete();
    }
}
